package core;

import java.util.Scanner;

import core.field.Field;

public class Player {
	private String name;
	private Konto konto;
	
	private boolean won;
	private boolean lost;
	private Dice[] dice = new Dice[2];
	
	private Field[] fieldsOwned = new Field[50];
	private int indexOfFields = 0;
	private int position = 0;
	
	public void addFieldToPlayer(Field f){
		fieldsOwned[indexOfFields] = f;
		indexOfFields++;
	}
	
	public void removeOwnedFields(){
		for ( int i =0; i<fieldsOwned.length; i++){
			fieldsOwned[i] = null;
		}
	}
	
	public Field[] returnFields(){
		Field[] temp = new Field[indexOfFields];
		for(int i = 0; i<indexOfFields; i++){
			temp[i] = fieldsOwned[i];
		}
		return temp;
	}
	
	public Player(String name){
		this.name = name;
		konto = new Konto();
		
		won = false;
		dice[0] = new Dice();
		dice[1] = new Dice();
	}
	
	
	
	public Player() {
		
		konto = new Konto();
		
		won = false;
		dice[0] = new Dice();
		dice[1] = new Dice();
	}

	public void throwDice(){
		dice[0].hit();
		dice[1].hit();
	}
	
	public Dice[] getDice(){
		return dice;
	}
	
	public Konto getKonto(){
		return konto;
	}
	public String getName(){
		return name;
	}
	
	
	
	public int getPoints(){
		return konto.getPoints();
	}
	
	public boolean getWon(){
		if(konto.getPoints() >= 3000)
			won = true;
		else
			won = false;
		return won;
	}
	
	public boolean getLost(){
		if(konto.getPoints() == 0)
			lost = true;
		else
			lost = false;
		return lost;
	}

	public void setName(String name){
		this.name = name;
	}
	
	public void setName(){
		System.out.println("Write Name: ");
		Scanner sc = new Scanner(System.in);
		this.name = sc.nextLine();
		sc.close();
	}
	@Override
	public String toString(){
		return name;
	}
	
	public int getPosition(){
		return position;
	}

	public void setPosition(Dice[] d){
		int temp=position;
		
		
		for(Dice dice : d){
			temp += dice.getValue();
		}
		if(temp>21)
			temp = temp-22;
		this.position = temp;
	}
}
